<?php
namespace Home\Controller;

class CureRecordController extends CommonController{
    
    public function index(){
        $this->display();
    }
    
    //获取日期区内容
    public function getDateStr($year,$month){
        //那个月
        $year_month = $month < 10 ? $year.'-0'.$month : $year.'-'.$month;
        //那个月的透析记录
        $txArr = array();
        $list = D('CureRecord')->getRecordByMon($this->uid,$year_month);
        
        foreach($list as $k=>$v){
            $txArr[] = $this->phpToJsDate($v['tx_date']);
        }
        echo ','.implode(',',$txArr).',';
    }
    
    /**
     * 添加或删除透析记录
     * @param string $date
     * @param int $status
     */
    public function add($date = '', $status = 1){
        $date = $this->jsToPhpDate($date);
        if($status == 1){
            M('CureRecord')->add(array('uid'=>$this->uid,'tx_date'=>$date));
        }else{
            M('CureRecord')->where(array('uid'=>$this->uid,'tx_date'=>$date))->delete();
        }
    }
    
    //js日期格式转php格式
    public function jsToPhpDate($date){
        $arr = explode('-',$date);
        $arr[1] = $arr[1] < 10 ? '0'+$arr[1] : $arr[1];
        $arr[2] = $arr[2] < 10 ? '0'+$arr[2] : $arr[2];
        return $arr[0].'-'.$arr[1].'-'.$arr[2];
    }
    
    //php日期格式转js格式
    public function phpToJsDate($date){
        $arr = explode('-',$date);
        return intval($arr[0]).'-'.intval($arr[1]).'-'.intval($arr[2]);
    }
    
}
